package io.noties.markwon.base.html.iframe

import io.noties.markwon.base.MarkwonConfiguration
import io.noties.markwon.base.RenderProps
import io.noties.markwon.base.SpanFactory
import io.noties.markwon.base.image.AsyncDrawable
import io.noties.markwon.base.image.span.AsyncDrawableSpan
import io.noties.markwon.base.image.ImageProps


class IframeSpanFactory : SpanFactory {
    override fun getSpans(configuration: MarkwonConfiguration, props: RenderProps): Any {
        val posterDrawable = AsyncDrawable(
            ImageProps.DESTINATION.require(props),
            configuration.asyncDrawableLoader(),
            configuration.imageSizeResolver(),
            ImageProps.IMAGE_SIZE[props]
        )
        return AsyncIframeDrawableSpan(
            configuration.categoryTheme().currentTheme,
            posterDrawable,
            AsyncDrawableSpan.ALIGN_BOTTOM,
            ImageProps.REPLACEMENT_TEXT_IS_LINK[props, false],
            IframeProps.IFRAME_DESTINATION[props, ""]
        )
    }
}